package com.cman777.springc.mybatis.objecthandler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.cman777.springc.common.bean.enums.StateEnum;
import com.cman777.springc.web.holder.RequestInfoHolder;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * @author chenzhicong
 * @time 2020/3/17 6:02
 * @description
 */
@Log4j2
public class CustomMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createdDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "operatorId", String.class, RequestInfoHolder.getOperatorId());
        this.strictInsertFill(metaObject, "stateDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "state", StateEnum.class, StateEnum.VALID);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "stateDate", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "operatorId", String.class, RequestInfoHolder.getOperatorId());
    }


}
